<template>
  <div class="ffddsa">
    <div class="boxfvg1" v-for="(item) in DataList" :key="item.id">
      <span class="boxfvg1Ttles">{{ item.name }}</span>
      <div class="progress-barsdff1">
        <transition name="progress-bar-transition">
          <div class="progress-bar-fill" :style="{ width: item.progress + '%', backgroundColor: item.color }">
            <!-- <span class="progress-bar-label">{{ Math.floor(item.progress) }}</span> -->
          </div>
        </transition>
      </div>
      <span class="boxfvg1tootersss">{{ item.value }}</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      DataList: [],
      yuanShuJu:[],
      colorData: [
        "#5470c6",
        "#91cc75",
        "#fac858",
        "#ee6666",
        "#73c0de",
        "#3ba272",
        "#fc8452",
        "#9a60b4",
      ],
    };
  },
  methods: {
    // 请求接口，获取数据
    getDataList() {
      this.DataList = []
        this.yuanShuJu.forEach((items, index) => {
          this.DataList.push({
            id: items.id,
            value: parseFloat(items.count),
            name: items.suoshuhangye,
            color: this.colorData[index % this.colorData.length],
            progress: 0,
          });
        });
        this.startProgress();
    },
    startProgress() {
      const totalItems = 100;
      let current = 0;

      const timer = setInterval(() => {
        current++;
        this.DataList.forEach((item) => {
          item.progress = (current * item.value) / totalItems;
        });

        if (current === totalItems) {
          clearInterval(timer);
        }
      }, 1);
    },
  },
};
</script>

<style scoped>
 .boxfvg1 {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
  }
  
  .boxfvg1 .boxfvg1Ttles {
    width: 200px;
    margin-right: 10px;
    font-size: 16px;
    color: aliceblue;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* background-color: #fff; */
  }
  
  .boxfvg1 .boxfvg1tootersss {
    width: 30px;
    margin-left: 10px;
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgb(113, 251, 220);
  }
  
  .progress-barsdff1 {
    display: inline-block;
    width: 100%;
    height: 16px;
    background-color: rgb(38, 86, 178);
    border-radius: 10px;
    overflow: hidden;
  }
  
  .progress-bar-fill {
    height: 100%;
    border-radius: 8px;
  }
  
  .progress-bar-transition-enter-active,
  .progress-bar-transition-leave-active {
    transition: width 0.5s;
  }
  
  .progress-bar-transition-enter,
  .progress-bar-transition-leave-to {
    width: 0;
  }
  
  .progress-bar-label {
    position: absolute;
    top: 0;
    right: 8px;
    bottom: 0;
    display: flex;
    align-items: center;
    color: white;
    font-size: 12px;
  }
</style>